import { contextBridge, ipcRenderer } from 'electron'

// 暴露安全的 API 到渲染进程
contextBridge.exposeInMainWorld('electronAPI', {
  // Chat API
  initOpenAI: (apiKey: string) => ipcRenderer.invoke('chat:init', apiKey),
  sendMessage: (message: string, context: any[]) => 
    ipcRenderer.invoke('chat:send', message, context),
  speechToText: (audioData: Buffer) => 
    ipcRenderer.invoke('chat:speech-to-text', audioData),

  // PDF API
  mergePDF: (files: string[], options: any) => 
    ipcRenderer.invoke('pdf:merge', files, options)
})

// 类型声明
declare global {
  interface Window {
    electronAPI: {
      initOpenAI: (apiKey: string) => Promise<any>
      sendMessage: (message: string, context: any[]) => Promise<any>
      speechToText: (audioData: Buffer) => Promise<any>
      mergePDF: (files: string[], options: any) => Promise<any>
    }
  }
} 